package com.zohnblog.web.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
* 通过实现WebMvcConfigurer接口，可以添加额外的MVC配置（拦截器、格式化器、视图控制器和其他特性
* */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private BaseInterceptor baseInterceptor;
    @Autowired
    private IPInterceptor ipInterceptor;

    @Override
    // 重写addInterceptors()方法，注册自定义拦截器
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(baseInterceptor).excludePathPatterns("/user/**").excludePathPatterns("/templates/**")
                .excludePathPatterns("/back/**").excludePathPatterns("/assets/**").excludePathPatterns("/article_img/**");
        registry.addInterceptor(ipInterceptor).excludePathPatterns("/user/**").excludePathPatterns("/templates/**")
                .excludePathPatterns("/back/**").excludePathPatterns("/assets/**").excludePathPatterns("/article_img/**");
    }

//    /**
//     * 处理静态资源
//     * @param registry
//     * @author tyg
//     * @date 2020-09-02 10:26
//     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        /*
//         * addResourceHandler是访问路径前缀，参数可设置多个，以逗号分隔，例：/image/**,/css/**
//         * addResourceLocations是对应的资源路径，也可以设置多个。
//         */
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
//        registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
//        super.addResourceHandlers(registry);
//    }
}
